package com.householditemtwo.index.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.householditemtwo.common.entity.Carousel;
import com.householditemtwo.common.entity.Compary;
import com.householditemtwo.common.entity.News;
import com.householditemtwo.common.entity.Newstype;
import com.householditemtwo.common.entity.Product;
import com.householditemtwo.common.entity.Producttype;
import com.householditemtwo.common.utils.BaseServlet;
import com.householditemtwo.index.dao.IndexDao;
import com.householditemtwo.index.dao.NewsDao;

/**
 * 页面Servlet
 */
@WebServlet("/IndexServlet")
public class IndexServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;

	// 创建DAo
	IndexDao dao = new IndexDao();
	
		/**
		 * 跳转到首页
		 * @param request
		 * @param response
		 * @throws ServletException
		 * @throws IOException
		 */
	public void toIndex(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			
		//查询出轮播图
		List<Carousel> carouselList=dao.selectAllCarousel();
		
		//公司介绍
		List<Compary> comparyList=dao.selectAllCompary();
	
		//查询出产品分类
		List<Producttype> producttypeList=dao.selectAllProducttype();
	
		//查询出精选商品
		List<Product> produtList=dao.selectAllProduct();
		
		
		  //查询出精选新闻
		List<News> newsList=dao.selectNews();
		 
		
		//调用DAO查询出新闻分类
			List<Newstype> newstypeList=dao.selectNewstype();
			
		
		
	request.setAttribute("carouselList", carouselList);
	request.setAttribute("cpydeiIntro", comparyList.get(0).getCpydeiIntro());
	request.setAttribute("ptypeList",producttypeList);
	request.setAttribute("produtList",produtList);
		 request.setAttribute("newsList",newsList); 
		//转发到首页
		request.getRequestDispatcher("index.jsp").forward(request, response);
	}
	
	
	
	

}
